// pages/userInfo/userInfo.js
const app = getApp();
const {
  editName
} = require('../../config.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    avatar:'',
    name:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      avatar: options.avatar || '',
      name: options.name,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  changeName: function(){
    wx.navigateTo({
      url: '/pages/info_supply/info_supply?type=3',
    })
  },
  getUserInfo: function (e) {
    let that = this;
    wx.showModal({
      title: '更换头像',
      content: '以微信当前头像替换原头像',
      confirmColor: '#1E66CC',
      success(res) {
        if (res.confirm) {
          let userInfo = e.detail.userInfo
          wx.setStorageSync('userInfo', userInfo);
          app.appRequest({
            url: editName,
            method: 'POST',
            data: {
              avatar: userInfo.avatarUrl,
            },
            success: (res) => {
              if (res.code == 0) {
                that.setData({
                  avatar: userInfo.avatarUrl,
                })
              }
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
    
  }
})